<template>
  <div id="app">
    <transition
      :name="direction">
      <router-view></router-view>
    </transition>
    <!-- <router-view v-else="none"></router-view> -->
  </div>
</template>

<script>
//rem适配
new function (){
  var _self = this;
  _self.width = 750;
  _self.fontSize = 100;
  _self.widthProportion = function(){
    var p = (document.body&&document.body.clientWidth||document.getElementsByTagName("html")[0].offsetWidth)/_self.width;
    return p>1?1:p;
  };
  _self.changePage = function(){
     document.getElementsByTagName("html")[0].setAttribute("style","font-size:"+_self.widthProportion()*_self.fontSize+"px !important");
  }
  _self.changePage();
  window.addEventListener("resize",function(){_self.changePage();},false);
};

export default {
  name: 'App',
  data(){
    return{
      direction:'',
    }
  },
  watch:{
    //页面切换效果
    '$route':function(to, from){
      //title名字
      document.title = this.$route.name;
      // // 登录校验和排除不检测的页面
      // var except = ['register','password','module','wechat'],
      //     path = this.$route.path.substring(1,this.$route.path.length).split('/')[0];
      // const index = except.findIndex(item => item === path);
      // if(index < 0){
      //   if(!localStorage.UserInfo){
      //     this.$router.push({
      //       path:'/login'
      //     })
      //   }
      // };
      //切换效果
      // const toDepth = to.path.split('/').length;
      // const fromDepth = from.path.split('/').length;
      // if(to.path=='/index' || to.path=='/orderList' || to.path=='/message' || to.path=='/user'){
      //   this.direction = '';
      //   return false;
      // }
      // if(toDepth < fromDepth){
      //   this.direction = 'out';
      // }else if(toDepth == fromDepth){
      //   var tolevel = to.meta.level,
      //       fromlevel = from.meta.level;
      //       // debugger;
      //   if(tolevel && fromlevel && tolevel<fromlevel){
      //     this.direction = 'out';
      //   }else{
      //     this.direction = 'in';
      //   };
      // }
      // else{
      //   this.direction = 'in';
      // };
    },
  },
  created() {
    //字体变化
    if(localStorage.ftClass){
      document.body.setAttribute("class",localStorage.ftClass);
    }
    if(localStorage.ft){
      document.body.setAttribute("class",localStorage.ftClass);
      document.body.style.fontSize = localStorage.ft + 'px';
    }
    this.setWxConfig();
  },
  methods:{
    //微信初始化
    setWxConfig:function() {
      var url = location.href;
      var self = this;
      if (location.hash.length) {
        url = url.substr(0, url.indexOf(location.hash));
      }
      var request = {
          url: url
      };
      this.Ajax.post('getTicKet',request).then(function(resp) {
        if (resp.IsSuccess == true) {
            var data = resp.Data;
            //开始注册wx
            self.jWeixin.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: data.appId, // 必填，公众号的唯一标识
                timestamp: data.timestamp, // 必填，生成签名的时间戳
                nonceStr: data.nonceStr, // 必填，生成签名的随机串
                signature: data.signature, // 必填，签名，见附录1
                jsApiList: [
                    "scanQRCode",
                    "openLocation",
                    "getLocation",
                    "getLocalImgData",
                    "previewImage",
                    "chooseImage",
                    "getLocation",
                    "uploadImage",
                    "downloadImage",
                    "onMenuShareAppMessage",
                    "onMenuShareQQ",
                    "showMenuItems",
                    "menuItem:share:appMessage",
                    "menuItem:share:qq",
                    "hideOptionMenu",
                    "startRecord",
                    "stopRecord",
                    "playVoice",
                    "stopVoice",
                    "onVoiceRecordEnd",
                    "chooseWXPay"
                ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
            });
            self.jWeixin.hideOptionMenu();
        }
      });
    },
  },

}
</script>

<!-- 公共样式引入 -->
<style lang="less">
@import url('./style/common.less');
</style>
